< previous page page_8 next page >

Page 8
e10a6a0a59f035e870d90cca05b85fce.gif
' Set the object's Scale properties. 
Private Sub SetTheScale(ByVal obj As Object, _ 
    ByVal upper_left_x As Single, ByVal upper_left_y As Single, _ 
    ByVal lower_right_x As Single, ByVal lower_right_y As Single) 
    
    obj.ScaleLeft = upper_left_x 
    obj.ScaleTop = upper_left_y 
    obj.ScaleWidth = lower_right_x - upper_left_x 
    obj.ScaleHeight = lower_right_y - upper_left_y 
End Sub
Example program Bars2 is similar to program Bars except it uses the SetTheScale subroutine to define its coordinate system as shown in the following code.
e10a6a0a59f035e870d90cca05b85fce.gif
' Define the custom coordinate system.
SetTheScale Me, 0, 110, NUM_VALUES + 2, 10
Coordinate Overflow
Eventually, all coordinate systems must be converted into pixels for output to the computer's screen. No matter which ScaleMode you use, Visual Basic internally performs its calculations in pixels. These internally calculated coordinates are stored in signed integers, so they must lie between 32,768 and 32,767. If they do not, Visual Basic generates an overflow error.
Because it is the transformed coordinates that might overflow, the range of coordinates you can use depends on the coordinate system you are using. If you measure distances in pixels, you can use coordinate values between 32,768 and 32,767. If you use twips, you can use much larger coordinates because a large number of twips translates into a smaller number of pixels.
A typical computer screen might have 15 twips per pixel. In that case, you can use twip coordinate values up to 15 times as large as you can use pixel values. In other words, you can use coordinates between 491,520 and 491,505.
Similarly, a typical screen might display 96 pixels per inch. In that case, you can measure coordinates in inches between about 341.3 and 341.3 inches.
If your program generates overflow errors while drawing, you should determine whether your coordinate values are too large.
Scale Conversions
Drawing objects provide two functions, ScaleX and ScaleY, for translating between different scale modes. These functions take as parameters a coordinate value or length, the value's current coordinate system, and the desired coordinate system. For example, the following code converts 120 twips into pixels.
e10a6a0a59f035e870d90cca05b85fce.gif
dist_pixels = ScaleX(120, vbTwips, vbPixels)

 
< previous page page_8 next page >